package com.gewu.advertisement.core.common

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.module.kotlin.KotlinModule
import java.text.SimpleDateFormat
import java.util.*

/**
 * @author htt 2021/1/7
 */
internal object JacksonFactory {
    val objectMapper = ObjectMapper().apply {
        registerModule(
            KotlinModule(
                nullisSameAsDefault = true,
                nullToEmptyCollection = true,
                nullToEmptyMap = true
            )
        )
        dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA)
        disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
        enable(SerializationFeature.WRITE_ENUMS_USING_INDEX)
        enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)
    }
}